<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>教师后台-不学也通</title>
    <style>
        .container {
            min-height: 100vh;
        }

        #container .leftmenu {
            min-height: 100vh;
            background-color: #fff;
        }

        .link-secondary {
            text-decoration: none;
        }

        .link-secondary:hover {
            color: #0d6efd !important;
        }
    </style>
</head>

<body>
    <!-- container是bootstrap的居中窄显示方案 -->
    <div class="container bg-success-subtle">
        <div class="row">
            <div class="col-md-2 leftmenu" id="leftmenu">
            </div>
            <div class="col-md-9 kc ms-3">
                <div class="row mt-3 pd-1 border-bottom border-dark-subtle">
                    <div class="col-md-2">编辑班级</div>
                    <div class="col-md-1 offset-md-8">
                        <a class=" nav-link link-success" href="javascript:history.go(-1)">返回</a>
                    </div>
                </div>
                <div class="row mt-3">
                    <form>
                        <div class="mb-3 row">
                            <label for="class-code" class="col-sm-2 col-form-label">班级编号:</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="class-code" value="">
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label for="class-name" class="col-sm-2 col-form-label">班级名称:</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="class-name">
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label for="grade_code" class="col-sm-2 col-form-label">年级:</label>
                            <div class="col-sm-10">
                                <select class="form-select" name="" id="grade_code">
                                    <option selected>-- 请选择院系 --</option>
                                    <option value="2021">2021级</option>
                                    <option value="2022">2022级</option>
                                </select>
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label for="class_logo" class="col-sm-2 col-form-label">班级logo:</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="class_logo">
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label for="class_number" class="col-sm-2 col-form-label">班级人数:</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="class_number">
                            </div>
                        </div>
                        <div class="md-3 row">
                            <div class="col-sm-12">
                                <buttom type="button" class="btn btn-outline-primary">提交</buttom>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script type="module" src="../js/main.js"></script>
    <script src="../js/jquery.min.js"></script>
    <script src="../js/common.js"></script>
    <script>
        $(document).ready(function () {
            function getUrlParams(key) {// 获取网址中参数信息"key"中放属性名
                var url = window.location.search.substr(1);
                if (url == '') {
                    return false;
                }
                var paramsArr = url.split('&');
                for (var i = 0; i < paramsArr.length; i++) {
                    var combina = paramsArr[i].split("=");
                    if (combina[0] == key) {
                        return combina[1];
                    }
                }
                return false;
            }
            $.get(`https://unicloud.codecore.cn/ms/getClass?id=${getUrlParams("id")}}`, {}, function (params) {
                if (params.errCode == 0) {
                    let data = params.data;
                    $("#class_code").val(data.class_code)
                    $("#class_name").val(data.class_name)
                    $("#class_logo").val(data.class_logo)
                    $("#class_number").val(data.class_number)
                    $("#grade_code").val(data.grade_code)
                }
            })
            $(".btn-outline-primary").click(function () {
                let class_code = $("#class_code").val()
                let class_name = $("#class_name").val()
                let class_logo = $("#class_logo").val()
                let class_number = $("#class_number").val()
                let grade_code = $("#grade_code").val()
                $.post("https://unicloud.codecore.cn/ms/classUpdate", {
                    id:getUrlParams("id"),
                    class_code: class_code,
                    class_name: lass_name,
                    class_logo: class_logo,
                    class_number: class_number,
                    grade_code: grade_code,
                    school_code: 50709,
                    department_code: 200,
                    majors_code: 3
                }, function (params) {
                    if (params.errCode == 0) {
                        location.href = "./class.html"
                    } else {
                        alert("添加失败")
                    }
                })
            })
        })
    </script>
</body>

</html>